const mutations = {
  add(state,obj){
    let shopobj = state.list.find(n=>n.id == obj.id);
    if(!shopobj){
      state.list.push({
        id:obj.id,
        num:1
      })
    }else{
        shopobj.num++
    }
  },
  remove(state,obj){
    state.list.forEach((item,index)=>{
      if(item.id == obj.id){
        state.list.splice(index,1)
      }
    })
  },
  jia(state,index){
    state.list[index].num++
  },
  jian(state,index){
    state.list[index].num--
    if(!state.list[index].num){
      state.list.splice(index,1)
    }
  },
  clearAllCart(state){
    state.list = []
  }
};
export default mutations
